package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.media.Image;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.bumptech.glide.Glide;
import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.view.dialog.FullScreenDialog;
import com.jucai.pppeiyouclient.weidget.photo.PhotoView;

import java.util.List;

/**
 * Created by Mars-SC on 2017/6/8.
 */

public class SamplePagerAdapter extends PagerAdapter {

    private List<String> urls;
    private Context context;
    private FullScreenDialog dialog;

    public SamplePagerAdapter(Context context, List<String> urls) {
        this.urls = urls;
        this.context = context;
    }

    public void setDialog(FullScreenDialog dialog) {
        this.dialog = dialog;
    }

    @Override
    public int getCount() {
        return urls.size();
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_show_images, null, false);
        String url = urls.get(position);

        final ImageView photoView = (ImageView) view.findViewById(R.id.pv_photo);

        Glide.with(context).load(url).into(photoView);

        container.addView(view, AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
